package 力扣日常刷题.木22二月.第16天222;

import 力扣日常刷题.ListNode;

/**
 * @author 帅小伙
 * @date 2022/2/22
 * @description
 */
public class Demo135环形链表 {

    public boolean hasCycle(ListNode head) {
        if (head == null || head.next == null) return false;
        ListNode slow = head;
        ListNode fast = head.next;

        while (slow != fast) {
            if (slow == null || fast == null || fast.next == null) {
               return false;
            }
            slow = slow.next;
            fast = fast.next.next;
        }
        return true;
    }

}
